package cn.itcast.anli.dao.impl;

import cn.itcast.anli.dao.AccountDAO;
import cn.itcast.anli.domain.Account;
import cn.itcast.anli.utils.JDBCUtil;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;


public class AccountDAOIpml implements AccountDAO {
    JdbcTemplate template = new JdbcTemplate(JDBCUtil.getDataSource());
    @Override
    public Boolean Login(String username,String password) {
        //1.定义sql语句
        String sql = "SELECT * FROM ACCOUNT WHERE account = ? AND password = ?";
        //2.执行sql语句
        try {

            //如果能查找到数据，返回true
            Account account = template.queryForObject(sql, new BeanPropertyRowMapper<>(Account.class), username, password);
            return true;
        }catch (Exception e){
            //如果找不到数据，sql语句错误，返回false
            e.printStackTrace();
            return false;
        }

    }
}
